package com.xm.queue.task2;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class BaseQueue implements IQueue {
    @Override
    public void putTryAcquire(ITask task) throws InterruptedException {
//        log.info("111");
        while (true) {
            if (TaskUtil.tryPutAcquire()) {
                this.put(task);
                break;
            }
        }
    }

    @Override
    public ITask takeTryAcquire() throws InterruptedException {
//        log.info("222");
        while (true) {
            if (TaskUtil.tryTakeAcquire()) {
                return this.take();
            }
        }
    }

    @Override
    public ITask pollTryAcquire() throws InterruptedException {
//        log.info("333");
        while (true) {
            if (TaskUtil.tryTakeAcquire()) {
                return this.poll();
            }
        }
    }
}
